package com.wyp168.leetcode.entity;

/**
 * @ClassName SecondNum
 * @Title TODO
 * @Description TODO
 * @Author wyp168
 * @Date 2022/10/10 20:33
 */
public class SecondNum {

    public static void main(String[] args) {
        SecondNum solution = new SecondNum();
        int[] nums = {1,5,2,3,6,1};
        System.out.println(solution.findSecond(nums));
    }

    public int findSecond(int[] nums){
        int max=nums[0];
        int sec_max=Integer.MIN_VALUE;
        for (int i = 0; i < nums.length; i++) {
            if(nums[i]>max){
                sec_max=max;
                max=nums[i];
            }
            else{
                if(nums[i]>sec_max)
                    sec_max=nums[i];
            }
        }
        return sec_max;
    }
}
